<include file="__THEME__/public_header" />
<div class="content">
	<div class="wrap">
    	<div class="con_side">
        	<ul class="nav">
            	<li><a href="{:U('admin/Privilege/index')}">市级账号</a></li>
                <li class="cursor"><a href="{:U('admin/Privilege/show_area_user')}">区级账号</a></li>
                <li><a href="{:U('admin/Privilege/show_garden_user')}">园级账号</a></li>
            </ul>
        </div>
        <div class="con_main">
        	<div class="con_tit">
            	<ul class="con_link">
                    <li class="on"><a href="javascript:;">筛选</a></li>
                    <li><a href="{:U('admin/Privilege/create_area_user')}">新建用户</a></li>
                </ul>
                <div class="search_wrap">
                	<input class="search_inp" id="uname" type="text" value="" placeholder="按用户名搜索">
                    <input class="search_btn" type="submit" value="" onclick="select_filter();">
                </div>
            </div>
            <div class="con_box">
            	<ul class="slect_list2">
                    <li>
                        <div class="txt">选择省级：</div>
                        <div class="inp">
                            <select id="Province" onchange="selectArea(1);">
                                <option>----请选择----</option>
                                <volist name="province" id="province">
                                    <option value="{$province.area_id}">{$province.title}</option>
                                </volist>
                            </select>
                        </div>
                    </li>
                    <li>
                        <div class="txt">选择市级：</div>
                        <div class="inp">
                            <select id="City">
                                <option value="0">----请选择----</option>
                            </select>
                        </div>
                    </li>
                </ul>
            	<div class="action_link tc small">
                	<a class="save" href="javascript:select_filter();">确定</a>
                </div>
            </div>
            <div class="con_tit">
                <table class="table table_title t5_3">
                  <tbody><tr>
                    <td>用户名</td>
                    <td>登录名</td>
                    <td>密码</td>
                    <td>操作</td>
                  </tr>
                </tbody></table>
            </div>
            <div class="con_box">
                <table class="table table_list t5_3">
                  <tbody>
                    <if condition="$area_user['data']">
                      <volist name = "area_user['data']" id="user">
                          <tr>
                            <td id="uname{$user.uid}">{$user.uname}</td>
                            <td>{$user.email}</td>
                            <td id="pwd{$user.uid}">{$user.pwd}</td>
                            <td>
                                <a href="javascript:updateUser({$user.uid});">修改</a>
                            </td>
                          </tr>
                      </volist>
                      <else/>
                      暂无用户
                    </if>
                </tbody>
                <if condition="$area_user['html']">
                <tr>
                    <td colspan="4">{$area_user.html}</td>
                </tr>
                </if>
                </table>
            </div>
        </div>
    </div>
</div>
<div class="pop_wrap" id="pop_wrap" style="display:none;">
  <div class="pop_box">
      <div class="pop_head"><a class="close" href="javascript:close();">X</a>用户信息修改</div>
        <div class="pop_body">
          <dl class="diapei_dl">
              <dt>用户名：</dt>
                <dd>
                   <input type="text" id="name">
                </dd>
            </dl>
            <dl class="diapei_dl">
              <dt>密码：</dt>
                <dd>
                    <input type="text" id="pwd">
                </dd>
            </dl>
        </div>
        <ul class="pop_foot">
          <li><a href="javascript:close();">取消</a></li>
          <li><a href="javascript:doUpdateUser();">确定</a></li>
        </ul>
    </div>
</div>
<input type="hidden" id="uid">
<script>
  function selectArea(type){
      if(type==1){
          var pid=$("#Province").val();
          var name="City";
      }else{
          var pid=$("#City").val();
          var name="Area";
      }
      if(pid>0){
          $.ajax({
            type: "GET",
            url:"{:U('public/TestData/getArea')}",
            data:"pid="+pid,
            dataType:"json",
            success:function(data){
              $("#"+name).html("");
              $("#"+name).append("<option value='0'>----请选择----</option>");
              $.each(data,function(i,item){
                $("#"+name).append("<option value='"+item.area_id+"'>"+item.title+"</option>");
              }); 
            }
          });
      }
  }
  function select_filter(){
      var City=$("#City").val();
      var uname=$("#uname").val();
      window.location.href = "{:U('admin/Privilege/show_area_user')}"+"&City="+City+"&uname="+uname; 

  }
  function updateUser(id){
      $("#uid").val(id);
      $("#name").val($("#uname"+id).html());
      $("#pwd").val($("#pwd"+id).html());
      $("#pop_wrap").css("display","block");
  }
  function doUpdateUser(){
     var uid=$("#uid").val();
     var uname=$("#name").val();
     var pwd=$("#pwd").val();
     if(uname==""){
        alert("请输入用户名");
        return;
     }
     if(pwd==""){
        alert("请输入密码");
        return;
     }
     $.ajax({
        type: "POST",
        url:"{:U('admin/Privilege/doUpdateUser')}",
        data:"uid="+uid+"&uname="+uname+"&pwd="+pwd,
        dataType:"text",
        success:function(data){
          if(isNaN(data)){
            alert(data);
          }else{  
              close();
              select_filter();
          }
        }
      });
  }
  function close(){
      $("#uid").val("");
      $("#name").val("");
      $("#pwd").val("");
      $("#pop_wrap").css("display","none");
  }
</script>
<include file="__THEME__/public_footer" />